﻿Imports JPC.Medialibrary.DAL
Imports JPC.Medialibrary.BLL
Imports JPC.Medialibrary.UI
Imports System.Diagnostics

Partial Class DiskDrive
    Inherits System.Web.UI.Page

    Private _noResults As Boolean = False

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        System.Threading.Thread.Sleep(80)

        If Page.IsPostBack Then
            If Me.cmdArg.Value = "" Then
                If FilesMenu.IsDVD Then
                    ProcesarComando("", "PlayDVD", "")
                End If
            End If

            If Mid(Request("__EVENTARGUMENT"), 1, 4) = "@@@@" Then
                Breadcrumb.AddItem("Raiz", "InspectDirectory", "")
                Breadcrumb.Bind(lblLastBreadcrumb, lstBreadcrumb)
                lstMain.DataSource = New FilesMenu("", "CDROM")
                lstMain.DataBind()
            Else
                Breadcrumb.Bind(lblLastBreadcrumb, lstBreadcrumb)
                If Me.cmdName.Value <> "" Then
                    ProcesarComando(Me.btnText.Value, Me.cmdName.Value, Me.cmdArg.Value)
                    Me.cmdName.Value = ""
                    Me.cmdArg.Value = ""
                    Me.btnText.Value = ""
                End If
            End If
        Else
            MySession.BreadCrumbList = Nothing
            MySession.LastBreadcrumb = Nothing
        End If

    End Sub

    Private Sub ProcesarComando(ByVal Text As String, ByVal CommandName As String, ByVal CommandArgument As String)

        CommandArgument = CommandArgument.Replace("?", "\").Replace("*", "'")

        Select Case CommandName
            Case "Inicio"
                Response.Redirect("~/Start.aspx")

            Case "PlayDVD"
                Dim pr As Process = New Process
                pr.StartInfo.FileName = """C:\Program Files\Zoom Player\zplayer.exe"""
                pr.StartInfo.Arguments = """" + CommandArgument + """" + " /F /LOCKFS /Q /DVD /PLAY /MOUSEOFF /CLOSE"
                pr.Start()

                System.Threading.Thread.Sleep(5000)
                Response.Redirect("~/Start.aspx")

            Case "PlayVideo"
                Dim pr As Process = New Process
                pr.StartInfo.FileName = """C:\Program Files\Zoom Player\zplayer.exe"""
                pr.StartInfo.Arguments = """" + CommandArgument + """" + " /F /LOCKFS /Q /MEDIA /MOUSEOFF /CLOSE"
                pr.Start()

                System.Threading.Thread.Sleep(5000)

            Case "PlayAudio"
                Dim pr As Process = New Process
                pr.StartInfo.FileName = """C:\Program Files\Zoom Player\zplayer.exe"""
                pr.StartInfo.Arguments = "/F /LOCKFS /Q /CDPLAY /MOUSEOFF /CLOSE"
                pr.Start()

            Case "InspectDirectory"
                Dim blnAddItem As Boolean = False
                If MySession.LastBreadcrumb Is Nothing Then
                    blnAddItem = True
                Else
                    blnAddItem = CommandArgument <> "" Or (CommandArgument = "" And MySession.LastBreadcrumb.Text <> "Raiz")
                End If
                If blnAddItem Then
                    Breadcrumb.AddItem(Text, CommandName, CommandArgument)
                End If
                Breadcrumb.Bind(lblLastBreadcrumb, lstBreadcrumb)
                lstMain.DataSource = New FilesMenu(CommandArgument, "CDROM")
                lstMain.DataBind()
        End Select

    End Sub

    Protected Sub lstMain_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles lstMain.ItemDataBound

        If (e.Item.ItemType = ListViewItemType.DataItem) Then
            Dim btn As LinkButton = CType(e.Item.FindControl("btnMain"), LinkButton)
            Dim lbl As Label = CType(e.Item.FindControl("lblInfo"), Label)

            Dim dataItem As Object = CType(e.Item, ListViewDataItem).DataItem
            Dim pnlRow As Panel = CType(e.Item.FindControl("pnlRow"), Panel)
            Dim img As Image = CType(e.Item.FindControl("imgObjectType"), Image)

            Dim btnId As String = "'" + btn.ClientID + "'"

            Dim _listItem As ListItem = CType(dataItem, ListItem)
            btn.OnClientClick = "javascript:setAction('" + _listItem.CommandName.Trim + "','" + _listItem.CommandArgument.Trim.Replace("\", "?").Replace("'", "*") + "'," + btnId + ");"
            btn.Text = _listItem.Text.Trim
            Select Case _listItem.ObjectType
                Case "Folder"
                    img.ImageUrl = "~/Images/folder.png"
                Case "Video"
                    img.ImageUrl = "~/Images/video.png"
                Case "Audio"
                    img.ImageUrl = "~/Images/audio.png"
                Case "Image"
                    img.ImageUrl = "~/Images/imagen.png"
                Case Else
                    img.Visible = False
            End Select
            lbl.Text = _listItem.Info

            If _noResults Then
                'pnlRow.CssClass = "row"
                btn.OnClientClick = "javascript:return false;"
            End If
        End If

    End Sub

    Protected Sub lstBreadcrumb_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles lstBreadcrumb.ItemDataBound

        Breadcrumb.ItemDataBound(sender, e)

    End Sub

    Protected Sub lstBreadcrumb_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles lstBreadcrumb.ItemCommand

        Dim index As Integer = CInt(e.CommandArgument)
        Dim li As ListItem = MySession.BreadCrumbList(index)
        Breadcrumb.RemoveRange(index)
        ProcesarComando(li.Text, li.CommandName, li.CommandArgument)

    End Sub

End Class
